import { createSlice, PayloadAction } from '@reduxjs/toolkit'
export interface loginType {
  token: string
  refresh_token: string
  menuList: menuItemType[]
  menuListLine: menuItemType[]
}
export interface menuItemType {
  label: string
  key: string
  icon: string
  path?: string
  children?: menuItemType[]
}
const initialState: loginType = {
  token: '',
  refresh_token: '',
  menuList: [],
  menuListLine: [],
}
export const loginSlice = createSlice({
  name: 'login',
  initialState,
  reducers: {
    changeTokenAction(state, action: PayloadAction<string>) {
      state.token = action.payload
    },
    changeRefreshToken(state, action: PayloadAction<string>) {
      state.refresh_token = action.payload
    },
    changeMenuList(state, action: PayloadAction<menuItemType[]>) {
      state.menuList = action.payload
    },
    changeMenuListLine(state, action: PayloadAction<menuItemType[]>) {
      state.menuListLine = action.payload
    },
  },
})
export const { changeTokenAction, changeMenuList, changeMenuListLine, changeRefreshToken } = loginSlice.actions
export default loginSlice.reducer
